www.gusucode.com > XerCMS 携云PHP企业建站程序 v2015PHP源码程序 > XerCMS 携云PHP企业建站程序 v2015/XerCMS_v20150724/XerCMS_v20150724/XerCMS/Library/XerCMS_cache.php

    <?php
/**
 * @name     XERCMS
 * @author   Arno <XerCMS@163.com> [QQ:1328013]
 * @version  1.0.0
 * @link     http://www.XerCMS.com 
 */

!defined('XERCMS') && exit('Access Denied');

class Cache
{
     private $prefix = '.php';
     private $path   = '';
	public  $file   = '';
	 
     public function Set($path) {
	     $this->path = $path;
	}
     
	private function pos($str) {
	     return md5($str).$prefix;
	}
	 
     public function pop($file) {
	     return file_get_contents($this->path.$file);
	}
	 
     public function push($file,$data) {
	     $this->file = $this->path.$file.$this->prefix;
	     return file_put_contents($this->file,$data);
	}	

     static function template() {
	     DIR::deldir(INC.'Caches/template/',false);
	}
	 
     static function fetchSql($str,$time) {
          $file = INC.'Caches/fetchSql/'.md5($str).'.php';
          if($time == -1)  {
               return DB::fetch_all($str);    
          } else {
               if(empty($time)) {
                    $time = X::$CONFIG['expire'];
               }
               if(!file_exists($file) || filemtime($file) + $time < X::$G['time']) {
                    $Cache = DB::fetch_all($str);
                    file_put_contents($file,'<?php !defined(\'XERCMS\') && exit(\'Access Denied\'); return '.AtoS($Cache,true).'; ?>');
                    return $Cache; 
               } else return include($file);
          }
     }
     
	static function columnParent($id) {
		$column = DB::fetch_all('select id,mode,parent,name from xercms_column where  id = \''.$id.'\'');
	   	$column[0]['column'] = $column[0]['id'];
	   	$columns[] = $column[0];
	   	if($column[0]['parent'] != 0) {
	     	$columns[] = current(self::columnParent($columns[0]['parent']));
	   	}
	   	return $columns;
	}
	 
     static function column($id) {
		$columns = self::columnParent($id);
	   	unset($columns[0]);
	   	$len = count($columns) - 1;$arr = array();
	   	while($len >= 0) {
	     	$arr[] = $columns[$len];
			$len--;
	   	}
	   	ini('archives/nav/'.$id,AtoS($boards,true));
	} 
	 
	static function boardParent($id) {
	   	$board = DB::fetch_all('select bid,parent,name from xercms_forum_board where  bid = \''.$id.'\'');
	   	$boards[] = $board[0];
	   	if($board[0]['parent'] != 0) {
	     	$boards[] = current(self::boardParent($boards[0]['parent']));
	   	}
	   	return $boards;
	}
	 
     static function forum_board($id) {
	   	$boards = self::boardParent($id);
	   	unset($boards[0]);
	   	$len = count($boards) - 1;$arr = array();
	   	while($len >= 0) {
	     	$arr[] = $boards[$len];
			$len--;
	   	}
	   	ini('forum/nav/'.$id,AtoS($boards,true));
	}  
	 
     static function plugin() {
          $plugins = DB::fetch_all('SELECT * FROM xercms_hook_module');
          $cache = array();
          foreach($plugins as $p) {
               $cache[$p['order']][] = array('module'=>$p['module'],'type'=>$p['type'],'action'=>$p['action'],'file'=>$p['file'],'enter'=>$p['enter'],'class'=>$p['class'],'method'=>$p['method']);
          }
		$data = ini('kernel');
          foreach($cache as $k=>$v) {
               $data['hook_'.$k] = $v;
          }
          Data::build('kernel',$data);
     } 	 
}
?>